<?php

/* **************************************************************************
EstateAgent Improved - Joomla Component

File:					admin.gallery.html.php
Copyright:			2004 - 2006 by Darko Selesi

Year: 2007
Improved by: Manos Orfanoudakis - "vosk"
Homepage: 		http://www.eaimproved.eu
Version: 			1.3.x                     
License:			GNU/GPL http://www.gnu.org/copyleft/gpl.html
*************************************************************************** */

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

class EAGalleryHTML{
	function initGUI($ino,$objid,$msg){
		global $eaconf;
		?>
		<script language="javascript" type="text/javascript">
		<!--	
			function changeGUI(act) {
				var url = "index<?php echo $ino?>.php?option=com_estateagent&act=gallery&action="+act+"&objid=<?php echo $objid?>";		
				document.getElementById('iframe').src = url;	
			}
		-->	
		</script>
        <style type="text/css">
		   .optbackgr {
			background: #F1F3F5;
			border-bottom: 1px solid #cccccc;
			}
		</style>
    


		<table class="adminform" width="100%">
		<tr>
			<td  style="height:30px; background-color:black; color:white; padding-left:25px"><span style="font-size:14pt; font-weight:bold;"></span> GalleryManager (<?php echo $eaconf->ea_version;?>)</td>
			<td style="text-align:right; vertical-align:bottom; padding-right:20px; background-color:black"><a href="#" style="color:white" onClick="javascript:window.close()"><b>:: <?php echo _EA_GL_CLOSEWIN;?> ::</b></a></td>
		</tr>	
		<tr>
			<th colspan="2" class="optbackgr" style="height:25px; padding-left:25px">
				<div >
					<a href="#" onClick="javascript:changeGUI('upload')"><?php echo _EA_GL_MENU1;?></a> | 
					<a href="#" onClick="javascript:changeGUI('manage')"><?php echo _EA_GL_MENU2;?></a> 						  										
			  </div>
			</th>
		</tr>
		</table>
		  <iframe name="iframe" id="iframe" src="index<?php echo $ino?>.php?option=com_estateagent&act=gallery&action=start" width="100%" height="550px" marginwidth="0" marginheight="0"  scrolling="yes" frameborder="0" bgcolor="#f5f5f5"></iframe>
	
	
	<?php
	}
	
	function uploadGUI($ino,$objid,$msg){
		global $database,$mainframe,$eaconf,$mosConfig_live_site,$my;
		$obj = new EAObject($database);						
		$ai	= $obj->loadGallery($objid,0);
		if(!$ai)$ai=array();
		
		$cai = count($ai);
		$oi	= $obj->loadGallery($objid,1);
		if(!$oi)$oi=array();
		 ?>
		<script language="javascript" type="text/javascript">
		<!--						
			function checkUpload() {
      			var form = document.picform;

				if (form.title.value == ""){
					alert( "<?php echo _EAB_GL_ERROR1; ?>" );
					stop();
   				} 
				else
					form.submit();
			}
			
			aimg	= new Array();
			oimg = new Array();
			
			<?php 
				foreach($ai as $a) {
					if($a->path == "") $a->path = $eaconf->ea_picpath;
					echo "aimg['".$a->id."'] = new Image('".$a->id."','".$a->fname."','".$a->type."','".$a->path."');";
				}
				foreach($oi as $o) {
					if($o->path == "") $o->path = $eaconf->ea_picpath;
					echo "oimg['".$o->id."'] = new Image('".$o->id."','".$o->fname."','".$o->type."','".$o->path."');";
				}
			?>		
		-->
		</script>

		<table class="menubar" style="width:100%; visibility:visible;" cellspacing="0" cellpadding="0" border=0>
		<tr>
			<th colspan="2" ><span class="small"><?php echo $msg; ?></span></th>
		</tr>	
		</table>
		<form name="bindform" action="index<?php echo$ino?>.php?option=com_estateagent&act=gallery" method="post">
		<input type="hidden" name="objid" value="<?php echo $objid; ?>" />
		<input type="hidden" name="action" value="bind" />
		<input type="hidden" name="imglist" value="0" />
		<table class="menubar" style="width:100%; visibility:visible;" border=0>
		<tr>
			<td valign="top" width="50%">
				<fieldset>
				<table width="100%">
				<tr>
					<td valign="top"> 
						<fieldset><legend><?php echo _EA_GL_BINDTOOBJ;?></legend>
						<table style="width:100%; background-color:#f5f5f5" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td height="120px" width="45%" align="center" valign="top"><?php echo _EA_GL_AVAILIMAGES;?><br />
								<select name="glimages" size="7" multiple onChange="previewImageBind( 'glimages', 'view_image', '<?php echo $mosConfig_live_site; ?>' )">
								<?php
									foreach($ai as $a) {
							 			echo "<option value='".$a->id."'>".$a->fname.$a->type."</option>";
									}
								?>
								</select>	
							</td>
							<td width="10%" valign="middle">
								<input class="button" style="width:40px" type="button" value=">>" onClick="addSelectedToList('bindform','glimages','objimages')" title="<?php echo _EA_GL_ADDTO;?>" />
								<br /><input class="button" style="width:40px" type="button" value="<<" onClick="delSelectedFromList('bindform','objimages')" title="<?php echo _EA_GL_REMOVEFROM;?>" />
							</td>
							<td width="45%" align="center" valign="top"><?php echo _EA_GL_IMGTOLINK;?><br />
								<select name="objimages" size="7" multiple onChange="previewImageBind( 'objimages', 'view_image', '<?php echo $mosConfig_live_site; ?>' )">
								</select>
							</td>
						</tr>
						<tr>
							<td style="height:20px; text-align:right" colspan="2">&nbsp;</td>
							<td align="center">
								<input type="button" class="button" id="submitbind" name="submitbind" value="<?php echo _EA_GL_SAVELINKS;?>" onClick="javascript:saveBindings()">
							</td>
						</tr>
						</table>				
					</td>
					<td valign="top" width="50%">						
						<fieldset><legend><?php echo _EA_GL_OBJIMAGES;?></legend>
						<table style="width:100%; background-color:#f5f5f5" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td align="center" valign="top" height="120px" width="50%"><?php echo _EA_GL_CLKPREVIEW;?><br />
								<select name="files" size="7" multiple onChange="previewImageBind( 'files', 'view_image', '<?php echo $mosConfig_live_site; ?>' )">
								<?php
									foreach($oi as $o) {
							 			echo "<option value='".$o->id."'>".$o->fname.$o->type."</option>";
									}
								?>
								</select>
							</td>
							<td width="50%" valign="middle">
								<div align="center">
									<img name="view_image" src="/components/com_estateagent/pictures/nopic.png" height="110" alt="" />
								</div>
							</td>
						</tr>
						<tr>
							<td style="height:20px; text-align:center">								
								<input type="button" class="button" id="editIMG" name="editIMG" value="<?php echo _EA_GL_EDITIMAGES;?>" onClick="javascript:parent.changeGUI('manage')">
							</td>
							<td>&nbsp;</td>
						</tr>
					</td>			
				</tr>
				</table>
				</fieldset>
			</td>
		</tr>
		</table>	
		</form>		
		
		<form id="picform" name="picform" method="post" action="index<?php echo $ino?>.php?option=com_estateagent&act=gallery&action=uploadFile" enctype="multipart/form-data">
		<input type="hidden" name="objid" value="<?php echo $objid; ?>" />
		<table id="uploadform" class="menubar" style="width:100%; visibility:visible;" border=0>
		<tr>	
			<td>
				<fieldset>
				<table width="100%" cellpadding=2 cellspacing=0 border=0>
				<tr>
					<td width="50%" valign="top">
						<fieldset><legend><?php echo _EA_GL_UPLOADIMG;?></legend>
						<table style="width:100%; background-color:#f5f5f5" cellpadding=2 cellspacing=0 border=0>
						<tr>
 							<td style="width:20%; text-align:right"><?php echo _EAB_OBJ_EGLNFT; ?></td>
            				<td style="width:80%;"><input type="text" id="title" name="title" size="40" class="inputbox" maxlength="50" value="" /></td>
            			</tr>			
						<tr>
          					<td style="text-align:right; text-valign: top"><?php echo _EAB_OBJ_EGLNFD; ?><br />(Alt Text)</td>
            				<td><textarea class="inputbox" id="description" name="description" cols="33" rows="3"></textarea></td>
           				</tr>
						<tr>
							<td>&nbsp;</td>
							<td>
								<input class="inputbox" size="14" name="userfile" type="file" />&nbsp;<input class="inputbox" type="button" value="Upload" name="fileupload" onClick="javascript:checkUpload()" /><br />
							</td>
						</tr>
						</table>
						</fieldset>  						
  						<fieldset><legend><?php echo _EA_GL_UPLOADSETTINGS;?></legend>
						<table style="width:100%; background-color:#f5f5f5" cellpadding="2" cellspacing="0" border="0">
						<?php
						$status = ($my->gid <= 21)? "readonly" : "";
						?>
						<tr>
							<td style="width:25%; text-align:right"><?php echo _EA_GL_UPLOADDIR;?></td>
							<td style="width:75%;"><input type="text" name="picpath" size="40" value="<?php echo $eaconf->ea_picpath; ?>" <?php echo $status; ?>></td>
						</tr>						
						<tr>
							<td style="text-align:right"><?php echo _EA_GL_MAXFILESIZE;?></td>
							<td><input type="text" name="maxpicsize" size="6" value="<?php echo $eaconf->ea_maxpicsize; ?>" <?php echo $status; ?>> KB</td>
						</tr>
						</table>
						</fieldset>							
  					</td>
  					<td style="width:50%; text-valign:top" valign="top">						
						<fieldset><legend><?php echo _EA_GL_IMGSETTINGS;?></legend>	
						<table style="width:100%; background-color:#f5f5f5" cellpadding=2 cellspacing=0 border=0>			
						<tr>
							<?php $checked = ($eaconf->ea_imgprtn == 1)? " checked" : ""; ?>
							<td style="width:22%; text-align:right"><?php echo _EA_GL_IMGWIDTH;?></td>
							<td style="width:78%"><input type="text" name="imgwidth" value="<?php echo $eaconf->ea_imgwidth; ?>" size="6" maxlength="6"/>px&nbsp;&nbsp;
								<?php echo _EA_GL_IMGPROPORTIONS;?> <input type="checkbox" name="imgprtn" value="1" <?php echo $checked; ?> /><br /></td>
  						</tr>
  						<tr>
							<td style="text-align:right"><?php echo _EA_GL_IMGHEIGHT;?></td>
							<td><input type="text" name="imgheight" value="<?php echo $eaconf->ea_imgheight; ?>" size="6" maxlength="6" />px</td>
  						</tr>
  						<tr>
							<td style="text-align:right"><?php echo _EA_GL_IMGQUALITY;?></td>
							<td><input type="text" name="imgqulty" value="<?php echo $eaconf->ea_imgqulty; ?>" size="6" maxlength="6" />%</td>
  						</tr>
  						</table>
  						</fieldset>
  						<fieldset><legend><?php echo _EA_GL_THUMBSETTINGS;?></legend>
  						<table style="width:100%; background-color:#f5f5f5" cellpadding=2 cellspacing=0 border=0>
  						<tr>
							<td style="width:22%; text-align:right"><?php echo _EA_GL_CREATETHUMB;?></td>
							<td style="width:78%;"><input type="checkbox" name="createthumb" value="1" checked /></td>
  						</tr>
  						<tr>
							<td style="text-align:right"><?php echo _EA_GL_IMGWIDTH;?></td>				
							<td><input type="text" name="tbwidth" value="<?php echo $eaconf->ea_tbwidth; ?>" size="6" maxlength="6"/>px&nbsp;&nbsp;
								<?php echo _EA_GL_IMGPROPORTIONS;?> <input type="checkbox" name="tbprtn" value="1" checked /><br />  
							</td>
  						</tr>
  						<tr>
							<td style="text-align:right"><?php echo _EA_GL_IMGHEIGHT;?></td>
							<td><input type="text" name="tbheight" value="<?php echo $eaconf->ea_tbheight; ?>" size="6" maxlength="6">px</td>
  						</tr>
  						<tr>
							<td style="text-align:right"><?php echo _EA_GL_IMGQUALITY;?></td>
							<td><input type="text" name="tbqulty" value="<?php echo $eaconf->ea_tbqulty; ?>" size="6" maxlength="6" />%</td>
  						</tr>
  						</table>
						</fieldset>
					</td>
  				</tr>
  				</table>
  				</fieldset>
			</td>
		</tr>
		</table>
		</form>
        <?php
	
	
	}
	function manageGUI($ino,$objid,$msg){
		global $database,$mosConfig_live_site,$eaconf;
	?>
		<table class="menubar" style="width:100%; visibility:visible;" cellspacing="0" cellpadding="0" border=0>
		<tr>
			<th ><span class="small" ><?php echo $msg; ?></span></th>
		</tr>
		</table>
						
		        		
		<?php		
		$o = new EAObject($database);
		$images = $o->loadGallery($objid,1);
		$i=1;$pn = count($images);
        if($pn > 0){
        	echo "<table style='width:100%' border='0' cellspacing='0' cellpadding='0'>";
			foreach($images as $pic){ ?>
        		<tr>
        			<td>
        				<fieldset><legend><?php echo _EA_GL_IMAGE;?><?php echo $i; ?>&nbsp;&nbsp;<?php if($i==1) echo _EAB_GL_FIRSTPIC;?></legend>
        				<table style="width:100%; background-color:<?php if($i==1){ echo "#cad5ff";}else echo "#f5f5f5";?>" border=0>
        				<form action="index<?php echo $ino?>.php?option=com_estateagent&act=gallery" id="glform<?php echo $i; ?>" name="glform<?php echo $i; ?>" method="post"> 
        				<input type="hidden" id="action" name="action" value="" />
						<input type="hidden" name="objid" value="<?php echo $objid; ?>" />
						<input type="hidden" id="pid" name="pid" value="<?php echo $pic->id; ?>" />
	       				<tr>
        					<td rowspan="2" width="<?php echo $eaconf->ea_tbwidth; ?>px"><img src="<?php echo $mosConfig_live_site.$eaconf->ea_picpath."t".$pic->fname.$pic->type; ?>" alt="" border="0" ></td>
    						<td>&nbsp;</td>
    						<td height="20px"><input type="text" class="inputbox" id="title" name="title" size="40" maxlength="50" value="<?php echo $pic->title; ?>"></td> 
    						<td rowspan="2" style="width:15%; text-align:center;text-valign:middle">
    						<?php                
                			if($i > 1) { ?>
        						<a href="index<?php echo $ino?>.php?option=com_estateagent&act=gallery&action=orderup&objid=<?php echo $pic->objid; ?>&pid=<?php echo $pic->id;?>">
        						<img src="<?php echo $mosConfig_live_site; ?>/administrator/images/uparrow.png" width="12" height="12" border="0" alt="<?php echo _EAB_OBJ_EGLPUP; ?>"></a>
        					<?php 
        					}else{
        			 			echo "&nbsp;";
                			}         		
        					if ($i < $pn) { ?>
        						<a href="index<?php echo $ino?>.php?option=com_estateagent&act=gallery&action=orderdown&objid=<?php echo $pic->objid; ?>&pid=<?php echo $pic->id; ?>">
        						<img src="<?php echo $mosConfig_live_site; ?>/administrator/images/downarrow.png" width="12" height="12" border="0" alt="<?php echo _EAB_OBJ_EGLPDW; ?>"></a>
        						<?php
        					}else{
        						echo "&nbsp;";
        					}
        					?>
    						<br /><br /><input type="button" class="button" style="width:120px" onClick="javascript:changeImages('delete','<?php echo $i; ?>')" value="<?php echo _EAB_OBJ_EGLPDLT; ?>" /><br />
    									<input type="button" class="button" style="width:120px" onClick="javascript:changeImages('save','<?php echo $i; ?>')" value="<?php echo _EA_GL_SAVECHANGES;?>" /></td>
        				</tr>
  						<tr>
    						<td>&nbsp;</td>
							<?php //XXX: Multiline textfields EDIT -VOSK ?>
    						<td valign="top"><textarea class="inputbox" id="description" name="description" cols="35" rows="3"><?php echo str_replace("<br />","\n",$pic->description); ?></textarea></td>    			
  						</tr>
  						</form>
  						</table>
  						</fieldset>
  					</td>
  				</tr>
  				<?php
       			$i++;
       			}
			echo "</table>";
        }
        
		
		#echo "Other Files<br />";
		
		$files = $o->loadFiles($objid);
		$i=1;$pna = count($files);
        if($pna > 0){        	
			echo "<table style=\"width:100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";	
			foreach($files as $fl){ ?>
        		<tr>
        			<td>
        				<fieldset><legend><?php echo _EA_GL_FILE;?> <?php echo $i; ?></legend>
        				<table style="width:100%; background-color:#eef5cd" border=0>
        				<form action="index<?php echo $ino?>.php?option=com_estateagent&act=gallery&" id="fform<?php echo $i; ?>" name="fform<?php echo $i; ?>" method="post"> 
        				<input type="hidden" id="pid" name="pid" value="<?php echo $fl->id; ?>" />
        				<input type="hidden" id="action" name="action" value="" />
        				<input type="hidden" name="objid" value="<?php echo $objid; ?>" />
        				<tr>
        					<?php
							$fl->type = strtolower(substr($fl->type,-3));
							?>
							<td rowspan="2" style="width:<?php echo $eaconf->ea_tbwidth; ?>px; text-align:center"><img src="<?php echo $mosConfig_live_site."/components/com_estateagent/pictures/gui/".$fl->type.".png"; ?>" alt="" border="0"><br />
							<?php echo _EA_GL_FILETYPE . $fl->type; ?></td>
    						<td>&nbsp;</td>
    						<td height="20px"><input type="text" class="inputbox" id="title" name="title" size="40" maxlength="50" value="<?php echo $fl->title; ?>"></td> 
    						<td rowspan="2" style="width:15%; text-align:center;text-valign:middle">
    						<?php                
                			if($i > 1) { ?>
        						<a href="index<?php echo $ino?>.php?option=com_estateagent&act=gallery&action=orderup&objid=<?php echo $fl->objid; ?>&pid=<?php echo $fl->id;?>">
        						<img src="<?php echo $mosConfig_live_site; ?>/administrator/images/uparrow.png" width="12" height="12" border="0" alt="<?php echo _EAB_OBJ_EGLPUP; ?>"></a>
        					<?php 
        					}else{
        			 			echo "&nbsp;";
                			}         		
        					if ($i < $pna) { ?>
        						<a href="index<?php echo $ino?>.php?option=com_estateagent&act=gallery&action=orderdown&objid=<?php echo $fl->objid; ?>&pid=<?php echo $fl->id; ?>">
        						<img src="<?php echo $mosConfig_live_site; ?>/administrator/images/downarrow.png" width="12" height="12" border="0" alt="<?php echo _EAB_OBJ_EGLPDW; ?>"></a>
        						<?php
        					}else{
        						echo "&nbsp;";
        					}
        					?>
    						<br /><br /><input type="button" class="button" style="width:100px" onClick="javascript:changeFiles('delete','<?php echo $i; ?>')" value="<?php echo _EA_GL_DELETEFILE; ?>" /><br />
    									<input type="button" class="button" style="width:100px" onClick="javascript:changeFiles('save','<?php echo $i; ?>')" value="<?php echo _EA_GL_SAVECHANGES;?>" /></td>
        				</tr>
  						<tr>
    						<td>&nbsp;</td>
							<?php //XXX: Multiline textfields EDIT -VOSK ?>
    						<td valign="top"><textarea class="inputbox" id="description" name="description" cols="35" rows="3"><?php echo str_replace("<br />","\n",$fl->description); ?></textarea></td>    			
  						</tr>
  						</form>
  						</table>
  						</fieldset>
  					</td>
  				</tr>
  				<?php
       			$i++;
       			}
				echo "</table>";	
        	}
	
	}
	function startGUI(){
		global $mosConfig_live_site;
		?>
        <div id="art" style="position:absolute; top:65px; left:0px; width:100%; text-align:center;">
			<br /><br /><br /><br /><img src="<?php echo $mosConfig_live_site; ?>/components/com_estateagent/pictures/gui/ealogo.png" border="0" />
		</div>	
        <?php 
	
	}

}


?>

